package com.atguigu.gmall.product.Rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.BaseCategoryService;
import com.atguigu.gmall.product.vo.CategoryTreeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/inner/rpc/product")
public class CategoryRpcController {

    @Autowired
    BaseCategoryService baseCategoryService;

    /**
     * 获取所有商品分类
     * @return
     */
    @GetMapping("/category/tree")
    public Result getCategoryTree(){

        List<CategoryTreeVo> list = baseCategoryService.getCategoryTree();
        return Result.ok(list);
    }

    /**
     * 根据c3Id获取skuInfo具体属于哪个分类
     * @param c3Id
     * @return
     */
    @GetMapping("/category/detail/{c3Id}")
    public Result<CategoryTreeVo> getCategoryTreeWithC3Id(@PathVariable("c3Id") Long c3Id){

        CategoryTreeVo categoryTreeVo = baseCategoryService.getCategoryTreeWithC3Id(c3Id);
        return Result.ok(categoryTreeVo);
    }
}
